package com.haibei.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.cache.SimpleImgLoaderLru;
import com.common.uitl.DateTool;
import com.haibei.R;
import com.haibei.adapter.bean.Article;
import com.haibei.cache.list.fanou.SimpleImageLoader;

public class ArticleAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<Article> mArrayListDataList;

	public ArticleAdapter(Activity activity, ArrayList<Article> datas) {
		this.activity = activity;
		this.mArrayListDataList = datas;
	}

	@Override
	public int getCount() {
		return mArrayListDataList.size();
	}

	@Override
	public Object getItem(int position) {
		return mArrayListDataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder vl;
		if (null == convertView) {
			convertView = View.inflate(activity, R.layout.item_article, null);
			vl = new ViewHolder();
			vl.textViewTitle = (TextView) convertView.findViewById(R.id.textViewTitle);
			vl.textViewContent = (TextView) convertView.findViewById(R.id.textViewContent);
			vl.timeAndAuthor = (TextView) convertView.findViewById(R.id.textViewTimeAndAuthor);
			vl.imageViewUrl = (ImageView) convertView.findViewById(R.id.imageViewImg);
			convertView.setTag(vl);
		} else {
			vl = (ViewHolder) convertView.getTag();
		}
		Article consult = mArrayListDataList.get(position);
		vl.textViewTitle.setText(consult.getTitle());
		vl.textViewContent.setText(consult.getShortContent());
		long time = Long.parseLong(consult.getPublishTime());

		vl.timeAndAuthor.setText(DateTool.getLongTime4Ymdhms(time) + " " + consult.getAuthor());
		SimpleImgLoaderLru.from(activity).displayImage(vl.imageViewUrl, consult.getCoverImg(), R.drawable.bg_default_consult);
//		SimpleImageLoader.display(vl.imageViewUrl, consult.getCoverImg(),R.drawable.bg_default_consult);
//		ImageManagerLru.from(activity).displayImage(vl.imageViewUrl, consult.getCoverImg(), R.drawable.bg_default_consult);
		
		return convertView;
	}

	class ViewHolder {
		TextView textViewTitle;
		TextView textViewContent;
		TextView timeAndAuthor;
		ImageView imageViewUrl;
	}

}
